# -*- coding: UTF-8 -*-
# server_assets
# @File : battleSide.py
# @Date : 2023-08-30
# @Author  : wuzhouhai
# @Desc:
import KBEngine
from KBEDebug import *

import random

PLAYER_PET = 2
MONSTER_MONSTER = 1
PLAYER_PLAYER = 3
PLAYER_WORLDBOSS = 4


# -------------游戏阵型-----------------------
# 4,1   1,4
# 5,2   2,5
# 6,3   3,6
# --------------------------------------------
class BattleSide(object):
    """战斗方类"""

    # hordeType:1 进攻方 2: 防守方
    def __init__(self, members, hordeType=1, matrixType=PLAYER_PET):
        """初始化战斗方"""
        self.matrixType = matrixType
        self.members = {1: None, 2: None, 3: None, 4: None, 5: None, 6: None}
        self.matrixSetting = {}
        self.lord = members[0].baseInfo.id  # 主将的ID
        # self.figure = members[0].profession.getFigure()#主角形象ID
        self.hordeType = hordeType
        if matrixType == MONSTER_MONSTER:
            #             print'创建怪物'
            self.hordeType = 2
            # monsterPositionList =  self.monsterChoosePosition(len(members))
            for role in members:
                if not role:
                    continue
                self.members[role.matrixId] = role
                self.matrixSetting[role.getBaseID()] = role.matrixId
        elif matrixType == PLAYER_PLAYER:
            for index, role in enumerate(members):
                if not role:
                    continue
                if index == 0:
                    self.setMatrixMember(5, role)
                    role.setMatrixId(5)
                elif index == 1:
                    self.setMatrixMember(4, role)
                    role.setMatrixId(4)
                elif index == 2:
                    self.setMatrixMember(6, role)
                    role.setMatrixId(6)
        elif matrixType == PLAYER_WORLDBOSS:
            position = 5
            self.members[position] = members[0]
            members[0].setMatrixId(position)
            self.matrixSetting[members[0].getBaseID()] = position

    def setMatrixMember(self, position, member):
        """设置成员位置"""
        self.members[position] = member
        self.matrixSetting[member.getBaseID()] = position

    def setHorderType(self, horderType):
        """设置阵营"""
        self.hordeType = horderType

    def getHordeType(self):
        """获取阵营类型"""
        return self.hordeType

    def petChoosePosition(self, profession):
        """武将根据职业选择位置"""
        position = 0
        choosePosionGroup = []
        if profession == 1:
            choosePosionGroup = [5, 4, 6, 1, 2, 3]
        elif profession == 2:
            choosePosionGroup = [1, 2, 3, 4, 5, 6]
        elif profession == 3:
            choosePosionGroup = [3, 1, 2, 4, 5, 6]

        for i in choosePosionGroup:
            if not self.members[i]:
                position = i
                break

        return position

    def monsterChoosePosition(self, count):
        """布怪规则"""
        choosePosionGroup = {1: [5], 2: [5, 1, 4], 3: [2, 1, 3, 5], 4: [2, 1, 3, 5, 6], 5: [2, 1, 3, 4, 5, 6],
                             6: [2, 1, 3, 4, 5, 6]}.get(count)
        return random.sample(choosePosionGroup, count)

    def getCharacterEyeNo(self, characterId):
        """获取角色在阵法中的位置"""
        eyeNo = self.matrixSetting.get(characterId)
        return eyeNo

    def getMembers(self):
        """获取战斗方成员信息"""
        return self.members

    def getLord(self):
        """获取主将的ID
        """
        return self.lord

